//
//  userData.m
//  扫码
//
//  Created by 鲍志刚 on 16/4/5.
//  Copyright © 2016年 鲍志刚. All rights reserved.
//

#import "UserData.h"
#import "NetworkTools.h"

@implementation UserData

+(instancetype)datasWithDict:(NSDictionary *)dic {
    UserData *userData = [[UserData alloc] init];
    
    [userData setValuesForKeysWithDictionary:dic];
    
    return userData;
}

-(void)setValue:(id)value forUndefinedKey:(NSString *)key {}

+ (void)datasWithURL:(NSString *)strUrl successBlock:(void (^)(NSArray *))successBlock errorBlock:(void (^)(NSError *))errorBlock {
    
    [[NetworkTools sharedTools] GET:strUrl parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *  _Nullable responseObject) {
        
        NSLog(@"%@",responseObject);
        
        NSArray *array = responseObject[@"data"];
        
//        NSLog(@"%@",array);

        NSMutableArray *mArray = [NSMutableArray arrayWithCapacity:10];
        for (NSDictionary *dic in array) {
            UserData *userData = [self datasWithDict:dic];
            [mArray addObject:userData];
        }
        if (successBlock) {
            successBlock(mArray.copy);
        }
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        if (errorBlock) {
            errorBlock(error);
        }
        
    }];

    
}


@end
